<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    /*重新设置样式*/
    .form-control {
        width: 196px !important;
        height: 34px !important;
        padding: 10px !important;
    }

</style>
<body class="hold-transition skin-blue sidebar-mini" onload="checkBrowser()">


<!--选择外购件库存模态框-->
<div class="modal fade" id="modal-select-purchase">
    <div class="modal-dialog" style="width: 1350px;">
        <div class="modal-content">
            <div class="modal-header" style="padding-bottom: 0px;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">外购件库在库明细信息</h4>
            </div>
            <div class="modal-body" style="padding-bottom: 5px;padding-top: 0px;">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box">
                            <div class="box-header" style="padding-bottom: 0px;">
                                <form id="queryForm" onkeydown="onKeyDown()">
                                    <div class="row" id="HiddenDiv">
                                        <div class="form-inline">
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>项目名称</label>
                                                <input type="text" id="ityProName" name="ityProName"
                                                       class="form-control"
                                                       placeholder="请输入项目名称">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>项目编号</label>
                                                <input type="text" id="ityProCode" name="ityProCode"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>供应商</label>
                                                <input type="text" id="ityBrand" name="ityBrand"
                                                       class="form-control"
                                                       placeholder="请输入项目编号">
                                            </div>


                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    物料描述
                                                </label>
                                                <input type="text" id="ityMatDesc" name="ityMatDesc"
                                                       class="form-control"
                                                       placeholder="请输入物料描述">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    SAP物料编码
                                                </label>
                                                <input type="text" id="itySapCode" name="itySapCode"
                                                       class="form-control"
                                                       placeholder="请输入SAP物料编码">
                                            </div>

                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>跟踪号</label>
                                                <input type="text" id="ityTrackCode" name="ityTrackCode"
                                                       class="form-control"
                                                       placeholder="请输入跟踪号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    库位
                                                </label>
                                                <input type="text" id="ityPosition" name="ityPosition"
                                                       class="form-control"
                                                       placeholder="请输入库位">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>箱号</label>
                                                <input type="text" id="ityCaseNo" name="ityCaseNo"
                                                       class="form-control"
                                                       placeholder="请输入箱号">
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>
                                                    生产状态
                                                </label>
                                                <select style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width:90px!important;"
                                                        id="proProductionStatus" name="proProductionStatus"
                                                        class="form-control select">
                                                    <option value="" selected="selected">全部</option>
                                                    <option value="-1">无状态</option>
                                                    <option value="1">未开始</option>
                                                    <option value="2">执行中</option>
                                                    <option value="3">已完成</option>
                                                    <option value="4">取消</option>
                                                    <option value="5">暂缓</option>
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>仓库</label>
                                                <select id="ityWhiId"
                                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;"
                                                        class="form-control select" name="ityWhiId">
                                                </select>
                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <label>是否串料</label>
                                                <select style="padding: 0px!important;text-align: center!important;text-align-last: center!important;width: auto!important;"
                                                        class="form-control select"
                                                        name="ityChangeFlag">
                                                    <option value="">全部</option>
                                                    <option value="100">是</option>
                                                    <option value="1">串入</option>
                                                    <option value="2">串出</option>
                                                    <option value="3">先入后出</option>
                                                    <option value="200">否</option>
                                                </select>
                                            </div>

                                            <div class="form-group"
                                                 style="margin-left: 10px;margin-right: 10px;margin-bottom: 5px;">
                                                <label class="control-label" style="width:85px;text-align: right">
                                                    制单日期范围
                                                </label>

                                                <input name="startTime" type="text" class="form-control datepicker"
                                                       style="width:100px!important;text-align: center!important;"
                                                       readonly="readonly"/>-
                                                <input name="endTime" type="text" class="form-control datepicker"
                                                       style="width:100px!important;text-align: center!important;"
                                                       readonly="readonly"/>

                                            </div>
                                            <div class="form-group" style="margin-right: 10px;margin-bottom: 5px;">
                                                <button type="button" class="btn btn-success" id="btn_inventorySearch">
                                                    搜索
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div id="toolbarPanel">
                                <button type="button" style="width: 82px;height: 34px;position: fixed;right: 15%"
                                        class="btn btn-info"
                                        id="btn-selectMaterial-commit">确定
                                </button>
                            </div>
                            <div class="box-body"
                                 style="padding-top: 0px;padding-bottom: 0px;height: 600px">
                                <table id="inventoryQueryTable" class="table table-bordered " width="100%"
                                       data-height="500">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer" style="padding-top: 5px;">

                <button type="button" style="width: 82px;height: 34px;" class="btn btn-default" data-dismiss="modal">
                    取消
                </button>
            </div>
        </div>
    </div>

</div>
<section class="content-header">
    <h1>领料出库单</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">

                    <div class="row">
                        <div class="form-inline">
                            <div class="form-group" style="margin: 5px">
                                <label>领料人</label>
                                <input type="text" id="odrTakePerson" name="odrTakePerson" class="form-control"
                                       placeholder="领料人">
                            </div>
                            <div class="form-group" style="margin: 5px">
                                <label>出库日期</label>
                                <input type="text" id="odrDate" name="odrDate" class="form-control datepicker"
                                       th:value="${currentDate}"
                                       readonly="readonly">
                            </div>
                            <div class="form-group" style="margin: 5px">
                                <label>摘要</label>
                                <input type="text" id="odrRemark" name="odrRemark" class="form-control"/>
                            </div>
                            <div class="form-group" style="margin: 5px">
                                <label>制单人</label>

                                <input type="text" id="odrMakePerson" name="odrMakePerson" class="form-control"
                                       th:value="${userName}"
                                       readonly="readonly"/>
                            </div>
                            <div class="form-group" style="margin: 5px">
                                <label>出库车间</label>
                                <select type="text" id="odrTakeWorkshopId" name="odrTakeWorkshopId"
                                        class="form-control select2"
                                        style="padding: 0px!important;text-align: center!important;text-align-last: center!important;">
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-inline">
                            <div class="form-group"
                                 shiro:hasAnyPermissions="purwar:puroutwar:view,mecwar:outwar:view,ykwar:outwar:view"
                                 style="margin: 5px">
                                <button id="open-modal" type="button" class="btn btn-info">
                                    选择
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <div id="hot"/>
                </div>
                <div style="text-align: right;margin-top: 10px">
                    <button type="button" id="btn-save"
                            shiro:hasAnyPermissions="purwar:puroutwar:edit,mecwar:outwar:edit,ykwar:outwar:edit"
                            class="btn btn-success file-contract btn-file" style="width: 82px;height: 34px">保存
                    </button>
                </div>
            </div>
        </div>
    </div>
</section>
<div id="printDiv" width="100%" style="display: none">
    <div style="padding-bottom: 10px;text-align:center;vertical-align: middle;">
        <div style="font-size: 20px;vertical-align: middle;display:inline-block;font-weight:bold">
            辽宁忠旺机械设备制造有限公司出库单
        </div>
    </div>
    <table style="font-size: 12px;width: 100%;line-height: 20px">
        <tr>
            <td>使用部门：<span id="printUseDept" style="padding-left: 5px"></span></td>
            <td>制单人：<span id="printMakeOrderPerson" style="padding-left: 5px"></span></td>
            <td>出库日期：<span id="printOdrDate" style="padding-left: 5px"></span></td>
            <td>单据编号：<span id="printOdrCode" style="padding-left: 5px"></span></td>
        </tr>
        <tr>
            <td colspan="2">摘要：<span id="printOdrRemark" style="padding-left: 5px"></span></td>
            <td colspan="2">领料人：<span id="printTakePerson" style="padding-left: 5px"></span></td>
        </tr>
    </table>
    <div id="table-box">
    </div>
    <table style="font-size: 16px;width: 100%;margin-top: 10px">
        <tr>
            <td width="45%">物资保管员签字：</td>
            <td>领件人员签字：</td>
        </tr>
    </table>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var bTable;
    var hTable;
    var selectIdArray = new Array();

    /**
     * 回车检测
     * */
    function onKeyDown(event) {
        let e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 13) { // enter 键
            js.table.refresh(bTable);
        }
    }
    /**
     * 检测浏览器
     * */
    function checkBrowser() {
        if (!checkBrowserFun()) {
            alert("尊敬的客户，您使用浏览器不是谷歌浏览器，请使用谷歌浏览器访问本系统！");
            location.href = ctx + "overview/index";
        }
    }
    function checkBrowserFun() {
        let is360 = false;
        let isIE = false;
        let isFirefox = false;
        let isChrome = false;
        let isEdge = false;
        let broName = 'Runing';
        let str = '';
        let strStart = 0;
        let strStop = 0;
        let arr = new Array();
        let temp = '';
        let userAgent = window.navigator.userAgent; //包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
        /*alert(userAgent);*/
        //FireFox
        if (userAgent.indexOf('Firefox') != -1) {
            isFireFox = true;
            /*broName = 'FireFox浏览器';*/
            strStart = userAgent.indexOf('Firefox');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号')

        }
        //Edge
        if (userAgent.indexOf('Edge') != -1) {
            isEdge = true;
            /*broName = 'Edge浏览器';*/
            strStart = userAgent.indexOf('Edge');
            temp = userAgent.substring(strStart);
            broName = temp.replace('/', '版本号');
        }
        //IE浏览器
        if (userAgent.indexOf('NET') != -1 && userAgent.indexOf("rv") != -1) {
            isIE = true;
            /*broName = 'IE浏览器'; */
            strStart = userAgent.indexOf('rv');
            strStop = userAgent.indexOf(')');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('rv', 'IE').replace(':', '版本号');
        }
        //360极速模式可以区分360安全浏览器和360极速浏览器
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") < 0 && userAgent.indexOf("Firefox") < 0) {
            if (navigator.javaEnabled()) {
                is360 = true;
                broName = '360安全浏览器-极速模式';
            } else {
                is360 = true;
                broName = '360极速浏览器-极速模式';
            }
        }
        //360兼容
        if (userAgent.indexOf('WOW') != -1 && userAgent.indexOf("NET") != -1 && userAgent.indexOf("MSIE") != -1 && userAgent.indexOf("rv") < 0) {
            is360 = true;
            broName = '360兼容模式';
        }
        //Chrome浏览器
        if (userAgent.indexOf('WOW') < 0 && userAgent.indexOf('Chrome') > 0 && userAgent.indexOf("Edg") < 0) {
            isChrome = true;
            /*broName = 'Chrome浏览器';*/
            strStart = userAgent.indexOf('Chrome');
            strStop = userAgent.indexOf(' Safari');
            temp = userAgent.substring(strStart, strStop);
            broName = temp.replace('/', '版本号');
        }
        return isChrome;
    }
        /**
     *@FunctionName: initBrowserDataBase
     *@Description: 复选复选框
     *@Author: 徐一贺
     *@CreateDate: 2020/6/20 14:11
     *@Phone: 18241927380
     *@Version: v 1.0.0
     */
    function checkCheckBox() {
        for (var i = 0; i < selectIdArray.length; i++) {
            $('input[name="cb_inventory"]').each(function (index, data) {
                if ($(this).attr("data") == selectIdArray[i]) {
                    $(this).prop("checked", true);
                }
            });
        }
    }

    /**
     *@FunctionName: checkedFun
     *@Description: 复选框改变事件函数
     *@Author: 徐一贺
     *@CreateDate: 2020/6/20 14:46
     *@Phone: 18241927380
     *@Version: v 1.0.0
     */
    function checkedFun(obj) {
        if ($(obj).prop("checked")) {
            selectIdArray.push($(obj).attr("data"));
        } else {
            if (arr instanceof selectIdArray) {
                var index = arr.indexOf($(obj).attr("data"));
                if (index > -1) {
                    arr.splice(index, 1);
                }
            }
        }
    }

    /**
     *@FunctionName: findWarehouseList
     *@Description: 获取仓库列表
     *@Author: 徐一贺
     *@CreateDate: 2020/3/24 15:31
     *@Phone: 18241927380
     *@Version: 1.0.0
     */
    function findWarehouseList() {
        js.ajax({
            url: ctx + 'common/warehouseInfo/list',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {

                    var mode = [[${mode}]];
                    $('#ityWhiId').empty();
                    if (mode == "pur") {
                        $('#ityWhiId').append('<option selected="selected" style="vertical-align: middle;text-align: center" value="-100">全部</option>');
                    } else if (mode == "mec") {
                        $('#ityWhiId').append('<option selected="selected" style="vertical-align: middle;text-align: center" value="-200">全部</option>');
                    } else if (mode == "yk") {
                        $('#ityWhiId').append('<option selected="selected" style="vertical-align: middle;text-align: center" value="-300">全部</option>');
                    } else if (mode != "mec" && mode == "yk") {
                        $('#ityWhiId').append('<option selected="selected" style="vertical-align: middle;text-align: center" value="">全部</option>');
                    }

                    for (var i = 0; i < result.data.rows.length; i++) {

                        if (mode == "pur" && (result.data.rows[i].whiTypePid == 1)) {
                            $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        }
                        if (mode == "mec" && (result.data.rows[i].whiTypePid == 3)) {
                            $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        }
                        if (mode == "yk" && (result.data.rows[i].whiTypePid == 2)) {
                            $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        }
                        // if (mode == "pur" && result.data.rows[i].whiCode != "机械备件库" && result.data.rows[i].whiCode != "机械备件库-营口" &&
                        //     result.data.rows[i].whiCode != "机械备件库消耗品库" && result.data.rows[i].whiCode != "机械油漆库" &&
                        //     result.data.rows[i].whiCode != "机械油漆库-营口" && result.data.rows[i].whiCode != "机械备件库消耗品库-营口" &&
                        //     result.data.rows[i].whiCode != "机械备件库液压库" && result.data.rows[i].whiCode != "机械备件库结晶器库") {
                        //     $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        // }
                        // if (mode == "mec" && (result.data.rows[i].whiCode == "机械备件库" || result.data.rows[i].whiCode == "机械备件库消耗品库" ||
                        //     result.data.rows[i].whiCode == "机械油漆库" || result.data.rows[i].whiCode == "机械备件库液压库" || result.data.rows[i].whiCode == "机械备件库结晶器库" )) {
                        //     $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        // }
                        // if (mode == "yk" && ( result.data.rows[i].whiCode == "机械备件库消耗品库-营口" || result.data.rows[i].whiCode == "机械油漆库-营口" ||
                        //     result.data.rows[i].whiCode == "机械备件库-营口" )) {
                        //     $('#ityWhiId').append('<option style="vertical-align: middle;text-align: center" value="' + result.data.rows[i].whiId + '">' + result.data.rows[i].whiName + '</option>');
                        // }
                    }
                    js.table.search(bTable);
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     *@FunctionName: findDeptList
     *@Description: 获取部门列表
     *@Author: 徐一贺
     *@CreateDate: 2020/3/24 13:27
     *@Phone: 18241927380
     *@Param:
     *@Return:
     *@Version:
     */
    function findDeptList() {
        js.post({
            url: ctx + "purWarOutManage/findDeptList",
            data: {},
            contentType: "application/json",
            success: function (result) {
                if (result.type == 'SUCCESS') {
                    var list = result.data;
                    $('#odrTakeWorkshopId').empty();
                    $('#odrTakeWorkshopId').append('<option style="vertical-align: middle;text-align: center" value="">请选择</option>');
                    for (var i = 0; i < list.length; i++) {
                        $('#odrTakeWorkshopId').append('<option style="vertical-align: middle;text-align: center" value="' + list[i].depId + '">' + list[i].depName + '</option>');
                    }
                }
            }
        });
    }

    var ids = [];
    var statusText = ["无状态", "执行中", "未开始", "暂缓", "已完成", "取消"];

    function selectAll(obj) {
        if ($(obj).prop("checked")) {
            $('input[name="cb_inventory"]').prop("checked", true);
            $('input[name="cb_inventory"]').each(function (index, data) {
                selectIdArray.push($(this).attr("data"));
            });
        }
        if ($(obj).prop("checked") == false) {
            $('input[name="cb_inventory"]').prop("checked", false);
            selectIdArray = new Array();
        }
    }

    $(function () {
        $("title").html($("title").html() + " —— 外购件领料出库");

        findDeptList();
        //加载列表数据
        bTable = js.table.init({
            id: 'inventoryQueryTable',
            url: ctx + "purWarOutManage/inventoryList",
            sortable: true,                                    // 是否启用排序
            sortStable: true,                                  // 设置为 true 将获得稳定的排序
            showColumns: true,
            showExport: false,
            toolbar: "#toolbarPanel",
            pageSize: 15,
            onLoadSuccess: function () {
                $('#btn_inventorySearch').prop('disabled', false).removeClass('disabled');
                $('#inventoryQueryTable thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#inventoryQueryTable tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                checkCheckBox();
            },
            columns: [
                {
                    title: '<input style="width: 16px;height: 16px" title="全选" onclick="selectAll(this)" type="checkbox" />',
                    width: '30',
                    field: 'ityDataStatus',
                    formatter: function (value, row, index) {
                        var ityDataStatus = "";
                        if (value == 2) {
                            ityDataStatus = 'disabled';
                        } else {
                            ityDataStatus = '';
                        }
                        ids.push('cb_inventory_' + row.ityId);
                        return '<input onchange="checkedFun(this)" style="width: 16px;height: 16px" ' + ityDataStatus + ' id="' + 'cb_inventory_' + row.ityId + '" name="cb_inventory" data="' + row.ityId + '"  type="checkbox" />';
                    }
                },
                {
                    title: '序号', field: 'ityId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    title: '串料标识', field: 'ityChangeFlag', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            return "";
                        } else {
                            var text = "";
                            var labelClass = "";
                            switch (value) {
                                case 1:
                                    text = "串入"
                                    labelClass = "badge label-success";
                                    break;
                                case 2:
                                    text = "串出"
                                    labelClass = "badge label-danger";
                                    break;
                                case 3:
                                    text = "先入后出"
                                    labelClass = "badge label-warning";
                                    break;
                                default:
                                    return "";
                            }
                            return '<label class="' + labelClass + '">' + text + '</label>';
                        }
                    }
                },
                {title: 'SAP<br>物料编码', field: 'itySapCode', width: '120'},
                {title: '物料描述', field: 'ityMatDesc', width: '200'},
                {title: '数量', field: 'ityNum', sortable: true},
                {title: '可用数量', field: 'ityAvaNum', sortable: true},
                {title: '单位', field: 'ityNumUnit'},
                {title: '供应商', field: 'ityBrand'},
                {title: '跟踪号', field: 'ityTrackCode'},
                {
                    title: '项目名称', field: 'ityProName', width: '200', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }
                },
                {
                    title: '项目编号', field: 'ityProCode', formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = "--";
                        }
                        return value;
                    }
                },

                {
                    title: '生产状态', field: 'proProductionStatus',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            value = 0;
                        }
                        return statusText[value];
                    }
                },
                {
                    title: '特殊说明', field: 'ityRemark',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            return "";
                        }
                        return value;
                    }
                },
                {title: '仓库', field: 'whiName'},
                {title: '库位', field: 'ityPosition'},
                {title: '箱号', field: 'ityCaseNo'},
                {
                    title: '在库类型', field: 'ityStockType',
                    formatter: function (value, row, index) {
                        if (value == undefined || value == null) {
                            return "";
                        } else if (value === 1) {
                            return "库存在库";
                        } else {
                            return "项目在库";
                        }

                    }
                },
                {title: '机械备件库备注类型', field: 'ityRemarkType', width: '100'},
                {title: '制单日期', field: 'odrMakeDate', width: '100'}
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn_inventorySearch").on('click', function () {
            $('#btn_inventorySearch').prop('disabled', true).addClass('disabled');
            js.table.search(bTable);
        });
        /**
         * 打开模态框
         */
        $('#open-modal').on('click', function () {
            findWarehouseList();
            js.modal.open('modal-select-purchase');
        });
        var rows;
        /**
         *可编辑表格
         */
        var process = function (data) {
            if ($.isEmptyObject(data.insertData)) {
                js.modal.warning("入库明细不允许为空！");
                return;
            }
            if ($("#odrTakeWorkshopId").val() == "") {
                js.modal.warning("请选择出库车间！");
                return;
            }
            $("#btn-save").attr("disabled",true);
            js.post({
                    url: ctx + "purWarOutManage/createRequestMaterial",
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    success: function (result) {
                        if (result.data.message == "单据保存成功！") {

                            if (hasP('purwar:puroutwar:print') || hasP('mecwar:outwar:print') || hasP('ykwar:outwar:view')) {
                                $("#table-box").empty();
                                $("#table-box").append('<table id="outOrderTable"\n' +
                                    '               style="font-size: 12px;text-align: center;border-right:1px solid;border-bottom:1px solid; border-collapse: collapse;"\n' +
                                    '               width="100%"\n' +
                                    '               cellspacing="0" cellpadding="1">\n' +
                                    '        </table>');
                                if (result.data.isChangeFlag > 0) {
                                    $("#outOrderTable").append('<THEAD style="display:table-header-group;">\n' +
                                        '<TR><td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">序号</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">跟踪号</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">物料编码</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">物料描述</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">区位</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">箱号</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;">单位</td>' +
                                        '<td rowspan="2" style="border-left: 1px solid;border-top: 1px solid;width: 80px;">单价</td>' +
                                        '<td colspan="3"  style="border-left: 1px solid;border-top: 1px solid;">现项目</td><td colspan="3"  style="border-left: 1px solid;border-top: 1px solid;">原项目</td>' +
                                        '</TR>' +
                                        '<TR><td style="border-left: 1px solid;border-top: 1px solid;">数量</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">项目编号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;width: 100px">项目名称</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">数量</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">项目编号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;width: 100px;">项目名称</td>' +
                                        '</TR></THEAD>');
                                    $("#outOrderTable").append('<tbody id="outOrderTableTbody"></tbody>');
                                    var list = result.data.insertData;
                                    $("#printOdrCode").html(result.data.odrCode);
                                    $("#printUseDept").html($("#odrTakeWorkshopId option:selected").text());
                                    $("#printMakeOrderPerson").html($("#odrMakePerson").val());
                                    $("#printOdrDate").html($("#odrDate").val());
                                    $("#printOdrRemark").html($("#odrRemark").val());
                                    $("#printTakePerson").html($("#odrTakePerson").val());
                                    for (var i = 0; i < list.length; i++) {
                                        if (list[i].odaMatDesc != null && list[i].odaMatDesc != '') {
                                            let odaTrackCode = "";
                                            if (list[i].odaTrackCode != undefined && list[i].odaTrackCode != null) {
                                                odaTrackCode = list[i].odaTrackCode;
                                            }
                                            let odaSapCode = "";
                                            if (list[i].odaSapCode != undefined && list[i].odaSapCode != null) {
                                                odaSapCode = list[i].odaSapCode;
                                            }
                                            let odaMatDesc = "";
                                            if (list[i].odaMatDesc != undefined && list[i].odaMatDesc != null) {
                                                odaMatDesc = list[i].odaMatDesc;
                                            }


                                            let odaNumUnit = "";
                                            if (list[i].odaNumUnit != undefined && list[i].odaNumUnit != null) {
                                                odaNumUnit = list[i].odaNumUnit;
                                            }
                                            let odaNum = "";
                                            if (list[i].odaNum != undefined && list[i].odaNum != null) {
                                                odaNum = list[i].odaNum;
                                            }
                                            let odaProCode = "";
                                            if (list[i].odaProCode != undefined && list[i].odaProCode != null) {
                                                odaProCode = list[i].odaProCode;
                                            }
                                            let odaProName = "";
                                            if (list[i].odaProName != undefined && list[i].odaProName != null) {
                                                odaProName = list[i].odaProName;
                                            }
                                            let odaNumSource = "";
                                            if (list[i].odaNumSource != undefined && list[i].odaNumSource != null) {
                                                odaNumSource = list[i].odaNumSource;
                                            }
                                            let odaProCodeSource = "";
                                            if (list[i].odaProCodeSource != undefined && list[i].odaProCodeSource != null) {
                                                odaProCodeSource = list[i].odaProCodeSource;
                                            }
                                            let odaProNameSource = "";
                                            if (list[i].odaProNameSource != undefined && list[i].odaProNameSource != null) {
                                                odaProNameSource = list[i].odaProNameSource;
                                            }
                                            let odaTakeType = "";
                                            if (list[i].odaTakeType != undefined && list[i].odaTakeType != null) {
                                                odaTakeType = list[i].odaTakeType;
                                            }
                                            let odaPosition = "";
                                            if (list[i].odaPosition != undefined && list[i].odaPosition != null) {
                                                odaPosition = list[i].odaPosition;
                                            }
                                            let odaCaseNo = "";
                                            if (list[i].odaCaseNo != undefined && list[i].odaCaseNo != null) {
                                                odaCaseNo = list[i].odaCaseNo;
                                            }
                                            $("#outOrderTableTbody").append("<tr>");
                                            //序号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + (i + 1) + "</td>");
                                            //跟踪号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaTrackCode + "</td>");
                                            //SAP物料编码
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaSapCode + "</td>");
                                            //物料描述
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaMatDesc + "</td>");
                                            //区位
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaPosition + "</td>");
                                            //箱号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaCaseNo + "</td>");
                                            //单位
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaNumUnit + "</td>");
                                            //单价
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\"></td>");
                                            //现项目
                                            //数量
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaNum + "</td>");
                                            //项目编号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProCode + "</td>");
                                            //项目名称
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProName + "</td>");
                                            //原项目
                                            //数量
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaNumSource + "</td>");
                                            //项目编号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProCodeSource + "</td>");
                                            //项目名称
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProNameSource + "</td>");
                                            $("#outOrderTableTbody").append("</tr>");
                                        }
                                    }
                                } else {
                                    $("#outOrderTable").append('<THEAD style="display:table-header-group;">\n' +
                                        '<TR><td style="border-left: 1px solid;border-top: 1px solid;">序号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">跟踪号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">物料编码</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">OA物料描述</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">数量</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">单位</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;width: 80px;">单价</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">供应商</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">项目编号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;width: 200px;">项目名称</td>' +

                                        '<td style="border-left: 1px solid;border-top: 1px solid;">领用类型</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">区位</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">箱号</td>' +
                                        '<td style="border-left: 1px solid;border-top: 1px solid;">特殊说明</td></TR></THEAD>');
                                    $("#outOrderTable").append('<tbody id="outOrderTableTbody"></tbody>');
                                    var list = data.insertData;
                                    $("#printOdrCode").html(result.data.odrCode);
                                    $("#printUseDept").html($("#odrTakeWorkshopId option:selected").text());
                                    $("#printMakeOrderPerson").html($("#odrMakePerson").val());
                                    $("#printOdrDate").html($("#odrDate").val());
                                    $("#printOdrRemark").html($("#odrRemark").val());
                                    $("#printTakePerson").html($("#odrTakePerson").val());
                                    for (var i = 0; i < list.length; i++) {
                                        if (list[i].odaMatDesc !== null && list[i].odaMatDesc !== '') {
                                            let odaTrackCode = "";
                                            if (list[i].odaTrackCode !== undefined && list[i].odaTrackCode !== null) {
                                                odaTrackCode = list[i].odaTrackCode;
                                            }
                                            let odaSapCode = "";
                                            if (list[i].odaSapCode !== undefined && list[i].odaSapCode !== null) {
                                                odaSapCode = list[i].odaSapCode;
                                            }
                                            let odaMatDesc = "";
                                            if (list[i].odaMatDesc !== undefined && list[i].odaMatDesc !== null) {
                                                odaMatDesc = list[i].odaMatDesc;
                                            }
                                            let odaNum = "";
                                            if (list[i].odaNum !== undefined && list[i].odaNum !== null) {
                                                odaNum = list[i].odaNum;
                                            }
                                            let odaNumUnit = "";
                                            if (list[i].odaNumUnit !== undefined && list[i].odaNumUnit !== null) {
                                                odaNumUnit = list[i].odaNumUnit;
                                            }
                                            let ityBrand = "";
                                            if (list[i].ityBrand !== undefined && list[i].ityBrand !== null) {
                                                ityBrand = list[i].ityBrand;
                                            }
                                            let odaProCode = "";
                                            if (list[i].odaProCode !== undefined && list[i].odaProCode !== null) {
                                                odaProCode = list[i].odaProCode;
                                            }
                                            let odaProName = "";
                                            if (list[i].odaProName !== undefined && list[i].odaProName !== null) {
                                                odaProName = list[i].odaProName;
                                            }
                                            let odaTakeType = "";
                                            if (list[i].odaTakeType !== undefined && list[i].odaTakeType !== null) {
                                                odaTakeType = list[i].odaTakeType;
                                            }
                                            let odaPosition = "";
                                            if (list[i].odaPosition !== undefined && list[i].odaPosition !== null) {
                                                odaPosition = list[i].odaPosition;
                                            }
                                            let odaCaseNo = "";
                                            if (list[i].odaCaseNo !== undefined && list[i].odaCaseNo !== null) {
                                                odaCaseNo = list[i].odaCaseNo;
                                            }
                                            let odaSpec = "";
                                            if (list[i].odaSpec !== undefined && list[i].odaSpec !== null) {
                                                odaSpec = list[i].odaSpec;
                                            }
                                            $("#outOrderTableTbody").append("<tr>");
                                            //序号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + (i + 1) + "</td>");
                                            //跟踪号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaTrackCode + "</td>");
                                            //SAP物料编码
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaSapCode + "</td>");
                                            //OA物料描述
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaMatDesc + "</td>");
                                            //数量
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaNum + "</td>");
                                            //单位
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaNumUnit + "</td>");
                                            //单价
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\"></td>");
                                            //供应商
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + ityBrand + "</td>");
                                            //项目编号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProCode + "</td>");
                                            //项目名称
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaProName + "</td>");
                                            //领用类型
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaTakeType + "</td>");
                                            //区位
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaPosition + "</td>");
                                            //箱号
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaCaseNo + "</td>");
                                            //特殊说明
                                            $("#outOrderTableTbody").append("<td style=\"border-left: 1px solid;border-top: 1px solid;\">" + odaSpec + "</td>");
                                            $("#outOrderTableTbody").append("</tr>");
                                        }
                                    }
                                }
                                $("#printDiv").show();
                                Print('#printDiv');
                                $("#printDiv").hide();
                            }
                        } else {
                            js.modal.warning(result.data);
                        }
                        $("#btn-save").attr("disabled",false);
                    }
                }
            );
        }
        hTable = js.hot.init({
            element: document.getElementById('hot'),
            data: {},
            formData: ["odrCode", "odrTakePerson", "odrDate", "odrRemark", "odrMakePerson", "odrTakeWorkshopId"],
            colHeaders: ['ID', 'ID1', '跟踪号', 'SAP物料编号', '物料描述', '数量', '单位','供应商', '项目编号', '项目名称','领用类型', '区位','箱号', '特殊说明', '在库类型','机械备件库备注类型'],
            fieldName: ['odaId', 'ityId', 'odaTrackCode', 'odaSapCode', 'odaMatDesc', 'odaNum', 'odaNumUnit','ityBrand', 'odaProCode', 'odaProName', 'odaTakeType', 'odaPosition','odaCaseNo', 'odaSpec', 'odaStockTypeText','odaRemarkType'],
            height: 640,
            minRows: 300,
            hiddenColumns: {
                columns: [0, 1],
                indicators: true
            },
            callBack: process,
            columns: [
                {
                    data: 'odaId',
                    type: 'numeric',
                    width: 40
                }, {
                    data: 'ityId',
                    type: 'numeric',
                    width: 40
                }, {
                    data: 'odaTrackCode',//跟踪号
                    type: 'text',
                    readOnly: true
                },
                {
                    data: 'odaSapCode',//物料编号
                    type: 'text',
                    readOnly: true
                },
                {
                    data: 'odaMatDesc',//物料描述
                    type: 'text',
                    readOnly: true
                },
                {
                    data: 'odaNum',//数量
                    type: 'numeric'
                },
                {
                    data: 'odaNumUnit',//单位
                    type: 'text', readOnly: true
                },
                {
                    data: 'ityBrand',//项目编号
                    type: 'text', readOnly: true
                },
                {
                    data: 'odaProCode',//项目编号
                    type: 'text', readOnly: true
                },
                {
                    data: 'odaProName',//项目名称
                    type: 'text',
                    readOnly: true
                },
                {
                    data: 'odaTakeType',//领用类型
                    type: 'text'
                },
                {
                    data: 'odaPosition',//区位
                    type: 'text', readOnly: true
                },
                {
                    data: 'odaCaseNo',//箱号
                    type: 'text', readOnly: true
                },
                {
                    data: 'odaSpec',//特殊说明
                    type: 'text'
                },
                {
                    data: 'odaStockTypeText',//在库类型
                    type: 'text', readOnly: true
                },
                {
                    data: 'odaRemarkType',//机械备件库备注类型
                    type: 'text', readOnly: true
                }


            ]
        });
        var ityIds = "";
        /**
         * 提交库存明细信息到可编辑表格
         */
        $('#btn-selectMaterial-commit').on('click', function () {
            if (selectIdArray === "") {
                js.modal.warning("请选择要出库的库存！");
                return;
            }
            var rows = js.hot._hot.getData();
            for (let i = 0; i < selectIdArray.length; i++) {
                for (let j = 0; j < rows.length; j++) {
                    if (Number(selectIdArray[i]) === Number(rows[j][1])) {
                        js.modal.warning("表中已包含选择库存，不可再次选择！");
                        return;
                    }
                }
            }
            var existRow = new Array();
            for (var i = 0; i < rows.length; i++) {
                if (rows[i][1] != null) {
                    var pInventoryModel = {
                        odaId: rows[i][0],
                        ityId: rows[i][1],
                        odaTrackCode: rows[i][2],
                        odaSapCode: rows[i][3],
                        odaMatDesc: rows[i][4],
                        odaNum: rows[i][5],
                        odaNumUnit: rows[i][6],
                        ityBrand: rows[i][7],
                        odaProCode: rows[i][8],
                        odaProName: rows[i][9],
                        odaTakeType: rows[i][10],
                        odaPosition: rows[i][11],
                        odaCaseNo: rows[i][12],
                        odaSpec: rows[i][13],
                        odaStockTypeText: rows[i][14],
                        odaRemarkType: rows[i][15]
                    }
                    existRow.push(pInventoryModel);
                }
            }
            if(selectIdArray === undefined || selectIdArray.length === 0){
                js.modal.warning("请选择！");
                return;
            }
            $.post(ctx + "purWarOutManage/findPInventoryList",
                {
                    ityIds: selectIdArray.join(','),
                    existRowStr: JSON.stringify(existRow)
                }
                ,
                function (result) {
                    if (result.type == web_status.SUCCESS) {
                        js.hot.loadData(result.data.rows);
                        js.modal.success(result.msg);
                        js.modal.hide('modal-select-purchase');
                        selectIdArray = new Array();
                    } else {
                        js.modal.warning(result.msg);
                    }

                }, 'json'
            );
        });
    });
</script>
</body>
</html>
